package xyz.hujf.bayes.test1;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author Hujf
 * @title: newTexts
 * @date 2021-05-08 16:14
 * @description: TODO
 */
public class newTexts {

    static final String[] INCOME= {"High","Medium","Low"};
    static final String[] IS_STU= {"Yes","No"};
    static final String[] RAGE= {"Fair","Excellent"};
    static final String[] IS_BUY= {"Yes","No"};
    public static void main(String[] args) {
        RandomAccessFile outputStream =null;
        try {
            outputStream= new RandomAccessFile("src\\main\\java\\xyz\\hujf\\bayes\\test1\\test.txt","rw");
            FileChannel channel = outputStream.getChannel();
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            long fileLength = outputStream.length();
            outputStream.seek(fileLength);
            for(int i=0;i<1000;i++) {
                byteBuffer.clear();
                StringBuilder builder = new StringBuilder();
                int num = (int) (Math.random() * 40+20) ;
                builder.append("\n"+num + "\t");
                num = (int) (Math.random() * 3);
                builder.append(INCOME[num] + "\t");
                num = (int) (Math.random() * 2);
                builder.append(IS_STU[num] + "\t");
                num = (int) (Math.random() * 2);
                builder.append(RAGE[num] + "\t");
                builder.append(IS_BUY[num]);
                System.out.println(builder.toString());
                byteBuffer.put(builder.toString().getBytes(StandardCharsets.UTF_8));
                byteBuffer.flip();
                channel.write(byteBuffer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
